<template>
	<!-- 20221227 -->
	<view class="user-config-index-page">
		<!-- 页面内容 -->
		<view class="page-content">
			
			<view class="group">
				<view class="line" @click="go(noticeUrl)">
					<view class="text-30 text-1a">用户协议</view>
					<view class="flex align-center">
						<text class="margin-left-10 tyIcon-arrow-right text-26 text-98"></text>
					</view>
				</view>

				<view class="line" @click="go(privacyUrl)">
					<view class="text-30 text-1a">隐私政策</view>
					<view class="flex align-center">
						<text class="margin-left-10 tyIcon-arrow-right text-26 text-98"></text>
					</view>
				</view>
				
				<!-- #ifdef APP-PLUS -->
				<view class="line" v-if="isLogin">
					<view class="text-30 text-1a">个性化推荐</view>
					<view>
						<ty-text-switch :is-on="isPersonalRecommend" @switchTab="changeSwitch"></ty-text-switch>
					</view>
				</view>
				<!-- #endif -->
				
			</view>
		</view>
		
		<!-- 页面浮层 -->
		<view class="page-layer">
			
		</view>
	</view>
</template>

<script>
	import user from "../api/user.js"
	export default {
		data() {
			return {
				// 用户协议链接
				noticeUrl: '/pages/common/richText?title=用户协议&url=project/api/Config/getAgreement&param=agreement',
				// 隐私政策链接
				privacyUrl: '/pages/common/richText?title=隐私政策&url=project/api/Config/getAgreement&param=privacy_policy',
				// 个性化开关是否打开
				isPersonalRecommend: false,
				// 用户是否登录
				isLogin: false
			}
		},

		onReady() {
			this.isLogin = this.cn.isLogin()
			if(this.isLogin){
				// 获取用户账号设置
				user.getAccountConfig().then(res => {
					if (res.code === 0) {
						this.isPersonalRecommend = res.data.is_personal_recommend ? true : false
					}
				})
			}
		},

		methods:{
			/**
			 * 个性化推荐开关切换状态
			 * @date 2022-12-27
			 */
			changeSwitch(e){
				let isPersonalRecommend = this.isPersonalRecommend ? 0 : 1
				user.updateAccountConfig(isPersonalRecommend).then(res => {
					if (res.code === 0) {
						this.isPersonalRecommend = !this.isPersonalRecommend
					}
				})
			}
		}
	}
</script>

<style>
	.group {
		padding: 0 30rpx;
		background-color: #fff;
	}

	.line {
		height: 100rpx;
		line-height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
</style>
